package Assignment10_IntersectingLines;

import java.util.ArrayList;
import java.util.Scanner;


public class Assignment10_IntersectingLines {

	static int counter = 0;

	public static void main(String[] args) {

		ArrayList<Points> al_V = new ArrayList<Points>();
		ArrayList<Points> al_H = new ArrayList<Points>();

		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		Scanner sc_nums = new Scanner(str);

		int v = sc_nums.nextInt();
		int h = sc_nums.nextInt();

		// System.out.println("Vertical :: " + v);
		// System.out.println("Horizontal :: " + h);

		while (sc.hasNext()) {

			for (int i = 0; i < v; i++) {
				String str_V = sc.nextLine();
				Scanner sc_v = new Scanner(str_V);

				Points pv = new Points(sc_v.nextInt(), sc_v.nextInt(),
						sc_v.nextInt()); // will this initialization fail

				// p.C = sc_v.nextInt();
				// p.A1 = sc_v.nextInt();
				// p.B1 = sc_v.nextInt();

				al_V.add(pv);

				// System.out.println("str_V :: " + str_V);

			}
			// System.out.println(al_V);

			for (int i = 0; i < h; i++) {
				String str_H = sc.nextLine();
				Scanner sc_H = new Scanner(str_H);

				Points ph = new Points(sc_H.nextInt(), sc_H.nextInt(),
						sc_H.nextInt());

				al_H.add(ph);

				// System.out.println("str_H :: " + str_H);
			}
			// System.out.println(al_H);

		}

		calculateIntersections(al_H, al_V);

	}

	private static void calculateIntersections(ArrayList<Points> al_H,
			ArrayList<Points> al_V) {
		for (int i = 0; i < al_V.size(); i++) {

			for (int j = 0; j < al_H.size(); j++) {

				if ((((al_H.get(j).A1) <= (al_V.get(i).C)) && ((al_V.get(i).C) <= (al_H
						.get(j).B1)))
						&& (((al_V.get(i).A1) <= (al_H.get(j).C)) && ((al_H
								.get(j).C) <= (al_V.get(i).B1)))) {

					counter++;
					// System.out.println("lines are intersecting");

				}

			}
		}
		System.out.println(counter);
	}

}
